import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)

var sto = {
    state: {
        animalInfo: {
            id: 0,
            animalName: '老虎' + '鬣狗',
            animalkind: '食肉动物'
        },
        count: 0,
        todos: [
            {
                id: 1, title: '001', done: true
            },
            {
                id: 2, title: '002', done: false
            },
            {
                id: 3, title: '003', done: true
            },
            {
                id: 4, title: '004', done: true
            }
        ]
    },
    mutations: {
        increamentBy: (state, num) => {
            state.count += num
        },
        increament: state => {
            state.num++
        }
    },
    actions: {

    },
    getters: {
        todoDone: state => {
            return state.todos.filter(item => item.done === true)
        },
        todoDoneCount: (state, getters) => {
            return getters.todoDone.length
        },
        animalNameNum: state => {
            return '数十只' + state.animalNameNum
        }
    }
}

/*{
  state: {
    count: 0,
    todos: [
      { id: 1, title: '001', done: true },
      { id: 2, title: '002', done: false },
      { id: 3, title: '003', done: false },
      { id: 4, title: '004', done: true },
      { id: 5, title: '005', done: true },
    ],
    animalInfo: {
        id:0,
        animalName:'',
        animalkind: '',
        access:[]
    }
  },
  mutations:{
    increament:function(state){
      state.count ++
    },
    increamentBy:(state,num) => {
        state.count += num
    }
  },
  getters: {
    todoDone:state=>{
      return state.todos.filter(item=>item.done === true)
    },
    todoDoneCount: (state,getters)=>{
      return getters.todoDone.length
    }
  }
} */

//实例化
const store = new Vuex.Store(sto)

console.log(store.state.animalInfo)

store.commit('increament', 10)

export default store